package com.lucky.ebidding.service;

import com.lucky.ebidding.dao.FileInfoDao;
import com.lucky.ebidding.dao.ZbInfoDao;
import com.lucky.ebidding.model.FileInfo;
import com.lucky.ebidding.model.FileInfoExample;
import com.lucky.ebidding.model.ZbInfo;
import com.lucky.ebidding.service.interfaces.FileServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName:FileService
 * Package:com.lucky.ebidding.service
 * Description:
 *
 * @Date:2020/3/18 10:22
 * @Author:857251389@qq.com
 */
@Service
public class FileService implements FileServiceI {

    @Autowired
    private FileInfoDao fileInfoDao;

    @Autowired
    private ZbInfoDao zbInfoDao;

    @Override
    public int insertFile(FileInfo fileInfo) {
        int i = fileInfoDao.insert(fileInfo);
        return i;
    }

    @Override
    public FileInfo selectById(Integer id) {

        FileInfo fileInfo = fileInfoDao.selectByPrimaryKey(id);

        return fileInfo;
    }

    @Override
    public FileInfo selectByZbId(Integer zbId) {
        ZbInfo zbInfo = zbInfoDao.selectByPrimaryKey(zbId);

        FileInfo fileInfo = fileInfoDao.selectByPrimaryKey(zbInfo.getFileId());

        return fileInfo;
    }

    @Override
    public FileInfo selectByFileName(String filename) {

        FileInfoExample fileInfoExample = new FileInfoExample();
        fileInfoExample.createCriteria().andFileNameEqualTo(filename);
        List<FileInfo> fileInfos = fileInfoDao.selectByExample(fileInfoExample);
        if(fileInfos.isEmpty()){
            return null;
        }
        return fileInfos.get(0);
    }
}
